import { defineConfig, loadEnv } from "vite";
import vue2 from "@vitejs/plugin-vue2";
import path from "path";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), ""); // 取到对应mode的文件
  return {
    // base: {},
    plugins: [
      vue2(),
      createSvgIconsPlugin({
        // 指定需要缓存的svg图标文件夹即需要识别的svg都应该放在这个文件夹下
        // iconDirs: [path.resolve(process.cwd(), 'src/assets/svgs')],
        // 或
        iconDirs: [path.resolve(__dirname, "./src/assets/icons/svg")],
        // 指定symbolId格式这里的配置与6.2步骤中的引入svg组件的name配置项写法有关
        symbolId: "icon-[dir]-[name]",
      }),
    ],
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"),
      },
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@import "@/assets/scss/style.scss";`,
        },
      },
    },
    server: {
      proxy: {
        // 代理配置
        "/caf": {
          target: "http://10.62.3.123:18085",
          secure: false,
          rewrite: (path) => path.replace(/^\/caf/, ""),
          changeOrigin: true,
          // headers: {
          //   Referer: 'https://example.com'
          // }
        },
      },
    },
  };
});
